﻿using Castle.Core.Resource;
using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;

namespace OutlookContactsSync.Domain
{
    public static class DependencyInjection
    {
        private static readonly object _initializationLock = new object();
        private static WindsorContainer _container;

        private static WindsorContainer Container
        {
            get
            {
                if (_container == null)
                {
                    lock (_initializationLock)
                    {
                        if (_container == null)
                        {
                            _container = new WindsorContainer(new XmlInterpreter(new ConfigResource("castle")));
                        }
                    }
                }
                return _container;
            }
        }

        public static T GetImplementationOf<T>()
        {
            return (T) Container[typeof (T)];
        }
    }
}